#include <cstdio>
#include <queue>

using namespace std;

struct Node
{
    int x, y, c;
    Node( ) { }
    Node( int _x, int _y, int _c )
        : x( _x ), y( _y ), c( _c ) { }
};

bool visit[ 10 ][ 10 ];
char map[ 10 ][ 11 ];
int n, m, in, step[ 10 ][ 10 ];

void init( )
{
    int i, j;
    for ( i = 0; i < n; i++ )
    {
        scanf("%s", map[ i ]);
        for ( j = 0; j < m; j++ )
            visit[ i ][ j ] = false;
    }
    in--;
}

void work( )
{
    int x, y;
    Node t;
    queue<Node> q;
    q.push( Node( 0, in, 0 ) );
    visit[ 0 ][ in ] = true;
    while ( !q.empty( ) )
    {
        t = q.front( );
        x = t.x;
        y = t.y;
        q.pop( );
        step[ x ][ y ] = t.c;
        if ( map[ t.x ][ t.y ] == 'N' )
            x--;
        if ( map[ t.x ][ t.y ] == 'S' )
            x++;
        if ( map[ t.x ][ t.y ] == 'E' )
            y++;
        if ( map[ t.x ][ t.y ] == 'W' )
            y--;
        if ( x < 0 || x >= n || y < 0 || y >= m )
        {
            printf("%d step(s) to exit\n", t.c + 1);
            break;
        }
        if ( visit[ x ][ y ] )
        {
            printf("%d step(s) before a loop of %d step(s)\n", step[ x ][ y ], t.c - step[ x ][ y ] + 1);
            break;
        }
        visit[ x ][ y ] = true;
        q.push( Node( x, y, t.c + 1 ) );
    }
}

int main( )
{
    while ( scanf("%d%d%d", &n, &m, &in) != EOF )
    {
        if ( n == 0 && m == 0 && in == 0 )
            break;
        init( );
        work( );
    }
    return 0;
}
